package cn.micai.base.lambda;

import java.util.Arrays;
import java.util.stream.Stream;

/**
 * 描述：在Java 8中，流不能被重用，一旦它被消费或使用，流将被关闭。
 * <p>
 *
 * @author: 赵新国
 * @date: 2018/6/21 17:58
 */
public class StreamIsClosedExample {

    public static void main(String [] args) {

        String [] array = {"a","b","c","d","e"};
        Stream<String> stream = Arrays.stream(array);

        // loop a stream
        stream.forEach(x->System.out.println(x));

        // reuse it to filter again! throws IllegalStateException
        // 回顾下面的例子，它将抛出一个非法的州异常，说“流是关闭的”
        long count = stream.filter(x -> "b".equals(x)).count();
        System.out.println(count);

    }
}
